home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 7 / Amiga Format AFCD07 (Dec 1996, Issue 91).iso / serious / shareware / programming / aros / exec / setfunction.c < prev    next >
C/C++ Source or Header  |  1996-09-12  |  3KB  |  101 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: setfunction.c,v 1.4 1996/08/13 13:56:08 digulla Exp $
  4.     $Log: setfunction.c,v $
  5.     Revision 1.4  1996/08/13 13:56:08  digulla
  6.     Replaced __AROS_LA by __AROS_LHA
  7.     Replaced some __AROS_LH*I by __AROS_LH*
  8.     Sorted and added includes
  9.  
  10.     Revision 1.3  1996/08/01 17:41:19  digulla
  11.     Added standard header for all files
  12.  
  13.     Desc:
  14.     Lang: english
  15. */
  16. #include <exec/execbase.h>
  17. #include <aros/libcall.h>
  18. #include "machine.h"
  19.  
  20. /*****************************************************************************
  21.  
  22.     NAME */
  23.     #include <clib/exec_protos.h>
  24.  
  25.     __AROS_LH3(APTR, SetFunction,
  26.  
  27. /*  SYNOPSIS */
  28.     __AROS_LHA(struct Library *, library,     A1),
  29.     __AROS_LHA(LONG,             funcOffset,  A0),
  30.     __AROS_LHA(APTR,             newFunction, D0),
  31.  
  32. /*  LOCATION */
  33.     struct ExecBase *, SysBase, 70, Exec)
  34.  
  35. /*  FUNCTION
  36.     Replaces a certain jumptable entry with another one. This function only
  37.     Forbid()s taskswitching but doesn't Disable() interrupts. You have
  38.     to do your own arbitration for functions which are callable from
  39.     interrupts.
  40.  
  41.     INPUTS
  42.     library     - Pointer to library structure.
  43.     funcOffset  - Offset of the jumpvector from the library base address in
  44.               bytes.
  45.     newFunction - New jumptable entry (pointer to the new function).
  46.  
  47.     RESULT
  48.     Old jumptable entry (pointer to the old function).
  49.  
  50.     NOTES
  51.     While it's more or less safe to patch a library vector with
  52.     SetFunction() it's not possible to safely remove the patch later.
  53.     So don't use this function if it can be avoided.
  54.  
  55.     EXAMPLE
  56.  
  57.     BUGS
  58.  
  59.     SEE ALSO
  60.     MakeLibrary(), MakeFunctions(), SumLibrary().
  61.  
  62.     INTERNALS
  63.  
  64.     HISTORY
  65.  
  66. ******************************************************************************/
  67. {
  68.     __AROS_FUNC_INIT
  69.  
  70.     APTR ret;
  71.  
  72.     /*
  73.     Arbitrate for the jumptable. This isn't enough for interrupt callable
  74.     functions - but it need not be.
  75.     */
  76.     Forbid();
  77.  
  78.     /* Mark the library as changed. */
  79.     library->lib_Flags|=LIBF_CHANGED;
  80.  
  81.     /* Get old vector. */
  82.     ret=GET_VEC((struct JumpVec *)((char *)library+funcOffset));
  83.  
  84.     /* Write new one. */
  85.     SET_VEC((struct JumpVec *)((char *)library+funcOffset),newFunction);
  86.  
  87.     /* And clear the instructiuon cache. */
  88.     CacheClearE((char *)library+funcOffset,LIB_VECTSIZE,CACRF_ClearI);
  89.  
  90.     /* Arbitration is no longer needed */
  91.     Permit();
  92.  
  93.     /* Sum the library up again */
  94.     SumLibrary(library);
  95.  
  96.     /* All done. */
  97.     return ret;
  98.     __AROS_FUNC_EXIT
  99. } /* SetFunction */
  100.  
  101.